/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package WeatherSystemMain;

import CommonValue.SystemTimer;
import DTO.ControlDTO;
import SocketBusiness.ClientConnect;
import DTO.PacketDTO;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class DataToAC extends ClientConnect {

    PacketDTO _dataToAC;

    public DataToAC(String systemSign, String ServerIP, int port, ControlDTO operation, PacketDTO _dataToAC) {
        super(systemSign, ServerIP, port, operation);
        this._dataToAC = _dataToAC;
    }

    @Override
    public void business() {
        boolean finish = false;
        do {
            try {
                Thread.sleep(SystemTimer.CheckReportSleep);
            } catch (InterruptedException ex) {
                Logger.getLogger(DataToAC.class.getName()).log(Level.SEVERE, null, ex);
            }

            if (!this.getOperation().getFlag()) {
                System.out.println(this.getSystemSign() + " DA DUNG HOAT DONG <<<<<<<<<<<<<<<<");
                continue;
            }

            synchronized (_dataToAC) {
                System.out.println("---------buffer to AC size : " + _dataToAC.getBuffer().size());
                try {
                    this.sendMessage(this._dataToAC);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(DataToAC.class.getName()).log(Level.SEVERE, null, ex);
                }
                _dataToAC.clearBuffer();
            }


        } while (!finish);
    }
}
